home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / interp / perl5.005.tar.gz / perl5.005.tar / perl5.005 / x2p / a2p.h < prev    next >
C/C++ Source or Header  |  1998-02-20  |  9KB  |  479 lines

  1. /* $RCSfile: a2p.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:09 $
  2.  *
  3.  *    Copyright (c) 1991-1997, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  * $Log:    a2p.h,v $
  9.  */
  10.  
  11. #define VOIDUSED 1
  12.  
  13. #ifdef WIN32
  14. #define _INC_WIN32_PERL5    /* kludge around win32 stdio layer */
  15. #endif
  16.  
  17. #ifdef VMS
  18. #  include "config.h"
  19. #else
  20. #  include "../config.h"
  21. #endif
  22.  
  23. #if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
  24. # define STANDARD_C 1
  25. #endif
  26.  
  27. #ifdef WIN32
  28. #undef USE_STDIO_PTR        /* XXX fast gets won't work, must investigate */
  29. #  ifndef STANDARD_C
  30. #    define STANDARD_C
  31. #  endif
  32. #  if defined(__BORLANDC__)
  33. #    pragma warn -ccc
  34. #    pragma warn -rch
  35. #    pragma warn -sig
  36. #    pragma warn -pia
  37. #    pragma warn -par
  38. #    pragma warn -aus
  39. #    pragma warn -use
  40. #    pragma warn -csu
  41. #    pragma warn -pro
  42. #  elif defined(_MSC_VER)
  43. #  elif defined(__MINGW32__)
  44. #  endif
  45. #endif
  46.  
  47. /* Use all the "standard" definitions? */
  48. #if defined(STANDARD_C) && defined(I_STDLIB)
  49. #   include <stdlib.h>
  50. #endif /* STANDARD_C */
  51.  
  52. #include <stdio.h>
  53.  
  54. #ifdef I_MATH
  55. #include <math.h>
  56. #endif
  57.  
  58. #ifdef I_SYS_TYPES
  59. #  include <sys/types.h>
  60. #endif
  61.  
  62. #ifdef USE_NEXT_CTYPE
  63.  
  64. #if NX_CURRENT_COMPILER_RELEASE >= 400
  65. #include <objc/NXCType.h>
  66. #else /*  NX_CURRENT_COMPILER_RELEASE < 400 */
  67. #include <appkit/NXCType.h>
  68. #endif /*  NX_CURRENT_COMPILER_RELEASE >= 400 */
  69.  
  70. #else /* !USE_NEXT_CTYPE */
  71. #include <ctype.h>
  72. #endif /* USE_NEXT_CTYPE */
  73.  
  74. #define MEM_SIZE Size_t
  75.  
  76. #ifdef STANDARD_C
  77. #   include <stdlib.h>
  78. #else
  79.     Malloc_t malloc _((MEM_SIZE nbytes));
  80.     Malloc_t calloc _((MEM_SIZE elements, MEM_SIZE size));
  81.     Malloc_t realloc _((Malloc_t where, MEM_SIZE nbytes));
  82.     Free_t   free _((Malloc_t where));
  83. #endif
  84.  
  85. #if defined(I_STRING) || defined(__cplusplus)
  86. #   include <string.h>
  87. #else
  88. #   include <strings.h>
  89. #endif
  90.  
  91. #if !defined(HAS_BCOPY) || defined(__cplusplus)
  92. #   define bcopy(s1,s2,l) memcpy(s2,s1,l)
  93. #endif
  94. #if !defined(HAS_BZERO) || defined(__cplusplus)
  95. #   define bzero(s,l) memset(s,0,l)
  96. #endif
  97.  
  98. #if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
  99. #define strchr index
  100. #define strrchr rindex
  101. #endif
  102.  
  103.  
  104. #ifdef I_TIME
  105. #   include <time.h>
  106. #endif
  107.  
  108. #ifdef I_SYS_TIME
  109. #   ifdef I_SYS_TIME_KERNEL
  110. #    define KERNEL
  111. #   endif
  112. #   include <sys/time.h>
  113. #   ifdef I_SYS_TIME_KERNEL
  114. #    undef KERNEL
  115. #   endif
  116. #endif
  117.  
  118. #ifndef MSDOS
  119. #  if defined(HAS_TIMES) && defined(I_SYS_TIMES)
  120. #    include <sys/times.h>
  121. #  endif
  122. #endif
  123.  
  124. #ifdef DOSISH
  125. # if defined(OS2)
  126. #   include "../os2ish.h"
  127. # else
  128. #   include "../dosish.h"
  129. # endif
  130. #else
  131. # if defined(VMS)
  132. #   define NO_PERL_TYPEDEFS
  133. #   include "vmsish.h"
  134. # endif
  135. #endif
  136.  
  137. #ifndef STANDARD_C
  138. /* All of these are in stdlib.h or time.h for ANSI C */
  139. Time_t time();
  140. struct tm *gmtime(), *localtime();
  141. char *strchr(), *strrchr();
  142. char *strcpy(), *strcat();
  143. #endif /* ! STANDARD_C */
  144.  
  145. #ifdef VMS
  146. #  include "handy.h"
  147. #else 
  148. #  include "../handy.h"
  149. #endif
  150.  
  151. #undef Nullfp
  152. #define Nullfp Null(FILE*)
  153.  
  154. #define Nullop 0
  155.  
  156. #define OPROG        1
  157. #define OJUNK        2
  158. #define OHUNKS        3
  159. #define ORANGE        4
  160. #define OPAT        5
  161. #define OHUNK        6
  162. #define OPPAREN        7
  163. #define OPANDAND    8
  164. #define OPOROR        9
  165. #define OPNOT        10
  166. #define OCPAREN        11
  167. #define OCANDAND    12
  168. #define OCOROR        13
  169. #define OCNOT        14
  170. #define ORELOP        15
  171. #define ORPAREN        16
  172. #define OMATCHOP    17
  173. #define OMPAREN        18
  174. #define OCONCAT        19
  175. #define OASSIGN        20
  176. #define OADD        21
  177. #define OSUBTRACT    22
  178. #define OMULT        23
  179. #define ODIV        24
  180. #define OMOD        25
  181. #define OPOSTINCR    26
  182. #define OPOSTDECR    27
  183. #define OPREINCR    28
  184. #define OPREDECR    29
  185. #define OUMINUS        30
  186. #define OUPLUS        31
  187. #define OPAREN        32
  188. #define OGETLINE    33
  189. #define OSPRINTF    34
  190. #define OSUBSTR        35
  191. #define OSTRING        36
  192. #define OSPLIT        37
  193. #define OSNEWLINE    38
  194. #define OINDEX        39
  195. #define ONUM        40
  196. #define OSTR        41
  197. #define OVAR        42
  198. #define OFLD        43
  199. #define ONEWLINE    44
  200. #define OCOMMENT    45
  201. #define OCOMMA        46
  202. #define OSEMICOLON    47
  203. #define OSCOMMENT    48
  204. #define OSTATES        49
  205. #define OSTATE        50
  206. #define OPRINT        51
  207. #define OPRINTF        52
  208. #define OBREAK        53
  209. #define ONEXT        54
  210. #define OEXIT        55
  211. #define OCONTINUE    56
  212. #define OREDIR        57
  213. #define OIF        58
  214. #define OWHILE        59
  215. #define OFOR        60
  216. #define OFORIN        61
  217. #define OVFLD        62
  218. #define OBLOCK        63
  219. #define OREGEX        64
  220. #define OLENGTH        65
  221. #define OLOG        66
  222. #define OEXP        67
  223. #define OSQRT        68
  224. #define OINT        69
  225. #define ODO        70
  226. #define OPOW        71
  227. #define OSUB        72
  228. #define OGSUB        73
  229. #define OMATCH        74
  230. #define OUSERFUN    75
  231. #define OUSERDEF    76
  232. #define OCLOSE        77
  233. #define OATAN2        78
  234. #define OSIN        79
  235. #define OCOS        80
  236. #define ORAND        81
  237. #define OSRAND        82
  238. #define ODELETE        83
  239. #define OSYSTEM        84
  240. #define OCOND        85
  241. #define ORETURN        86
  242. #define ODEFINED    87
  243. #define OSTAR        88
  244.  
  245. #ifdef DOINIT
  246. char *opname[] = {
  247.     "0",
  248.     "PROG",
  249.     "JUNK",
  250.     "HUNKS",
  251.     "RANGE",
  252.     "PAT",
  253.     "HUNK",
  254.     "PPAREN",
  255.     "PANDAND",
  256.     "POROR",
  257.     "PNOT",
  258.     "CPAREN",
  259.     "CANDAND",
  260.     "COROR",
  261.     "CNOT",
  262.     "RELOP",
  263.     "RPAREN",
  264.     "MATCHOP",
  265.     "MPAREN",
  266.     "CONCAT",
  267.     "ASSIGN",
  268.     "ADD",
  269.     "SUBTRACT",
  270.     "MULT",
  271.     "DIV",
  272.     "MOD",
  273.     "POSTINCR",
  274.     "POSTDECR",
  275.     "PREINCR",
  276.     "PREDECR",
  277.     "UMINUS",
  278.     "UPLUS",
  279.     "PAREN",
  280.     "GETLINE",
  281.     "SPRINTF",
  282.     "SUBSTR",
  283.     "STRING",
  284.     "SPLIT",
  285.     "SNEWLINE",
  286.     "INDEX",
  287.     "NUM",
  288.     "STR",
  289.     "VAR",
  290.     "FLD",
  291.     "NEWLINE",
  292.     "COMMENT",
  293.     "COMMA",
  294.     "SEMICOLON",
  295.     "SCOMMENT",
  296.     "STATES",
  297.     "STATE",
  298.     "PRINT",
  299.     "PRINTF",
  300.     "BREAK",
  301.     "NEXT",
  302.     "EXIT",
  303.     "CONTINUE",
  304.     "REDIR",
  305.     "IF",
  306.     "WHILE",
  307.     "FOR",
  308.     "FORIN",
  309.     "VFLD",
  310.     "BLOCK",
  311.     "REGEX",
  312.     "LENGTH",
  313.     "LOG",
  314.     "EXP",
  315.     "SQRT",
  316.     "INT",
  317.     "DO",
  318.     "POW",
  319.     "SUB",
  320.     "GSUB",
  321.     "MATCH",
  322.     "USERFUN",
  323.     "USERDEF",
  324.     "CLOSE",
  325.     "ATAN2",
  326.     "SIN",
  327.     "COS",
  328.     "RAND",
  329.     "SRAND",
  330.     "DELETE",
  331.     "SYSTEM",
  332.     "COND",
  333.     "RETURN",
  334.     "DEFINED",
  335.     "STAR",
  336.     "89"
  337. };
  338. #else
  339. extern char *opname[];
  340. #endif
  341.  
  342. EXT int mop INIT(1);
  343.  
  344. union u_ops {
  345.     int ival;
  346.     char *cval;
  347. };
  348. #if defined(iAPX286) || defined(M_I286) || defined(I80286)     /* 80286 hack */
  349. #define OPSMAX (64000/sizeof(union u_ops))    /* approx. max segment size */
  350. #else
  351. #define OPSMAX 50000
  352. #endif                             /* 80286 hack */
  353. EXT union u_ops ops[OPSMAX];
  354.  
  355. typedef struct string STR;
  356. typedef struct htbl HASH;
  357.  
  358. #include "str.h"
  359. #include "hash.h"
  360.  
  361.  
  362. /* A string is TRUE if not "" or "0". */
  363. #define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
  364. EXT char *Yes INIT("1");
  365. EXT char *No INIT("");
  366.  
  367. #define str_true(str) (Str = (str), (Str->str_pok ? True(Str->str_ptr) : (Str->str_nok ? (Str->str_nval != 0.0) : 0 )))
  368.  
  369. #define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%g)",Str->str_nval),buf) : "" )))
  370. #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
  371. #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_nval : str_2num(Str)))
  372. EXT STR *Str;
  373.  
  374. #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
  375.  
  376. /* Prototypes for things in a2p.c */
  377. int aryrefarg _(( int arg ));
  378. int bl _(( int arg, int maybe ));
  379. void dump _(( int branch ));
  380. int fixfargs _(( int name, int arg, int prevargs ));
  381. int fixrargs _(( char *name, int arg, int prevargs ));
  382. void fixup _(( STR *str ));
  383. int numary _(( int arg ));
  384. int oper0 _(( int type ));
  385. int oper1 _(( int type, int arg1 ));
  386. int oper2 _(( int type, int arg1, int arg2 ));
  387. int oper3 _(( int type, int arg1, int arg2, int arg3 ));
  388. int oper4 _(( int type, int arg1, int arg2, int arg3, int arg4 ));
  389. int oper5 _(( int type, int arg1, int arg2, int arg3, int arg4, int arg5 ));
  390. void putlines _(( STR *str ));
  391. void putone _(( void ));
  392. int rememberargs _(( int arg ));
  393. char * scannum _(( char *s ));
  394. char * scanpat _(( char *s ));
  395. int string _(( char *ptr, int len ));
  396. void yyerror _(( char *s ));
  397. int yylex _(( void ));
  398.  
  399. EXT int line INIT(0);
  400.  
  401. EXT FILE *rsfp;
  402. EXT char buf[2048];
  403. EXT char *bufptr INIT(buf);
  404.  
  405. EXT STR *linestr INIT(Nullstr);
  406.  
  407. EXT char tokenbuf[2048];
  408. EXT int expectterm INIT(TRUE);
  409.  
  410. #ifdef DEBUGGING
  411. EXT int debug INIT(0);
  412. EXT int dlevel INIT(0);
  413. #define YYDEBUG 1
  414. extern int yydebug;
  415. #endif
  416.  
  417. EXT STR *freestrroot INIT(Nullstr);
  418.  
  419. EXT STR str_no;
  420. EXT STR str_yes;
  421.  
  422. EXT bool do_split INIT(FALSE);
  423. EXT bool split_to_array INIT(FALSE);
  424. EXT bool set_array_base INIT(FALSE);
  425. EXT bool saw_RS INIT(FALSE);
  426. EXT bool saw_OFS INIT(FALSE);
  427. EXT bool saw_ORS INIT(FALSE);
  428. EXT bool saw_line_op INIT(FALSE);
  429. EXT bool in_begin INIT(TRUE);
  430. EXT bool do_opens INIT(FALSE);
  431. EXT bool do_fancy_opens INIT(FALSE);
  432. EXT bool lval_field INIT(FALSE);
  433. EXT bool do_chop INIT(FALSE);
  434. EXT bool need_entire INIT(FALSE);
  435. EXT bool absmaxfld INIT(FALSE);
  436. EXT bool saw_altinput INIT(FALSE);
  437.  
  438. EXT bool nomemok INIT(FALSE);
  439.  
  440. EXT char const_FS INIT(0);
  441. EXT char *namelist INIT(Nullch);
  442. EXT char fswitch INIT(0);
  443. EXT bool old_awk INIT(0);
  444.  
  445. EXT int saw_FS INIT(0);
  446. EXT int maxfld INIT(0);
  447. EXT int arymax INIT(0);
  448. EXT char *nameary[100];
  449.  
  450. EXT STR *opens;
  451.  
  452. EXT HASH *symtab;
  453. EXT HASH *curarghash;
  454.  
  455. #define P_MIN        0
  456. #define P_LISTOP    5
  457. #define P_COMMA        10
  458. #define P_ASSIGN    15
  459. #define P_COND        20
  460. #define P_DOTDOT    25
  461. #define P_OROR        30
  462. #define P_ANDAND    35
  463. #define P_OR        40
  464. #define P_AND        45
  465. #define P_EQ        50
  466. #define P_REL        55
  467. #define P_UNI        60
  468. #define P_FILETEST    65
  469. #define P_SHIFT        70
  470. #define P_ADD        75
  471. #define P_MUL        80
  472. #define P_MATCH        85
  473. #define P_UNARY        90
  474. #define P_POW        95
  475. #define P_AUTO        100
  476. #define P_MAX        999
  477.  
  478. EXT int an;
  479.